﻿<#
.SYNOPSIS
Convert manifest file definition to its documented definition Model

.DESCRIPTION
ManifestFileDefinition to create its documentation  

.PARAMETER sourceObject
Required. the file definition to transform

.PARAMETER ServerDefinition
Optional. The Manifest Server which contains the file synchronisation definition
If missing, the function will resolve this object
#>
function ConvertTo-DocumentedFolder
{
    Param( 
        [Parameter(Mandatory=$true,ValueFromPipeline=$true)]
        [PSObject] 
        $sourceObject,

        [Parameter(Mandatory=$false,ValueFromPipeline=$false)]
        [PSObject] 
        $ServerDefinition

    )
    Process
    {               
        $targetObject = Get-DocumentedBaseObject -SourceObject $sourceObject -ServerDefinition $ServerDefinition

        $targetObject | Add-Member -MemberType NoteProperty -Name Parent -Value $sourceObject.Parent.UniqueKey
        $targetObject | Add-Member -MemberType NoteProperty -Name Path -Value (Get-FullPath -Object $sourceObject)

        Write-Output $targetObject

    }
}

<#
.SYNOPSIS
Convert manifest file definition to its documented definition Model

.DESCRIPTION
ManifestFileDefinition to create its documentation  

.PARAMETER sourceObject
Required. the file definition to transform

.PARAMETER ServerDefinition
Optional. The Manifest Server which contains the file synchronisation definition
If missing, the function will resolve this object
#>
function ConvertTo-DocumentedFiles
{
    Param( 
        [Parameter(Mandatory=$true,ValueFromPipeline=$true)]
        [PSObject] 
        $sourceObject,

        [Parameter(Mandatory=$false,ValueFromPipeline=$false)]
        [PSObject] 
        $ServerDefinition

    )
    Process
    {               
        $targetObject = Get-DocumentedBaseObject -SourceObject $sourceObject -ServerDefinition $ServerDefinition

        #Get specific properties for DSC File Synchronization
        $DestinationPath = Get-FullPath -Object $sourceObject 
        $SourcePath = $null    
        if ($sourceObject.Source)
        {
            $SourcePath = Get-Value -Object $sourceObject -Value $sourceObject.Source
        }

        $targetObject | Add-Member -MemberType NoteProperty -Name SourcePath -Value $SourcePath
        $targetObject | Add-Member -MemberType NoteProperty -Name DestinationPath -Value $DestinationPath
        $targetObject | Add-Member -MemberType NoteProperty -Name IsDeclarationFile -Value ($SourcePath -eq $null)

        Write-Output $targetObject

    }
}

<#
.SYNOPSIS
Convert environment variable definition to its documented definition Model

.DESCRIPTION
ManifestEnvironmentVariableDefinition must have one property source which define the file to synchronize  

.PARAMETER sourceObject
Required. the environment variable definition to transform

.PARAMETER ServerDefinition
Optional. The Manifest Server which contains the file synchronisation definition
If missing, the function will resolve this object
#>
function ConvertTo-DocumentedEnvironmentVariable
{
    Param( 
        [Parameter(Mandatory=$true,ValueFromPipeline=$true)]
        [PSObject] 
        $sourceObject,

        [Parameter(Mandatory=$false,ValueFromPipeline=$false)]
        [PSObject] 
        $ServerDefinition

    )
    Process
    {
        $targetObject = Get-DscBaseObject -SourceObject $sourceObject -ServerDefinition $ServerDefinition

        #Get specific properties for Environment Variable
        $Name = Get-Value -Object $sourceObject -Value $sourceObject.Name
        $Value = Get-EnvironmentVariable -EnvironmentVariable $sourceObject
        $MergePattern = $sourceObject.MergePattern
        if (-not $MergePattern) {$MergePattern = ";"}

        $targetObject | Add-Member -MemberType NoteProperty -Name Name -Value $Name
        $targetObject | Add-Member -MemberType NoteProperty -Name Value -Value $Value
        $targetObject | Add-Member -MemberType NoteProperty -Name MergePattern -Value $MergePattern

        Write-Output $targetObject
    }
}